package com.swz.dcrm.ui.monthly;


import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.swz.dcrm.adpter.GlobalAdapter;
import com.swz.dcrm.model.BaseResponse;
import com.swz.dcrm.model.DailyTarget;
import com.swz.dcrm.model.MonthlyTarget;
import com.swz.dcrm.ui.base.BaseFragment;
import com.swz.dcrm.R;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.navigation.fragment.NavHostFragment;

import android.widget.ProgressBar;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;

import com.swz.dcrm.R;
import com.swz.dcrm.ui.daily.DailyTargetDetailFragmentArgs;
import com.swz.dcrm.ui.viewmodel.AnalyzeViewModel;

import javax.inject.Inject;

/**
 * A simple {@link Fragment} subclass.
 */
public class MonthlyTargetFragment extends BaseFragment {


    @BindView(R.id.tv_clue_convert_rate)
    TextView tvClueConvertRate;
    @BindView(R.id.tv_follow_rate)
    TextView tvFollowRate;
    @BindView(R.id.progress_bar1)
    ProgressBar progressBar1;
    @BindView(R.id.progress_bar2)
    ProgressBar progressBar2;

    @BindView(R.id.progress_bar3)
    ProgressBar progressBar3;

    @BindView(R.id.progress_bar4)
    ProgressBar progressBar4;

    @BindView(R.id.progress_bar5)
    ProgressBar progressBar5;

    @BindView(R.id.progress_bar6)
    ProgressBar progressBar6;

    @BindView(R.id.progress_bar7)
    ProgressBar progressBar7;
    @BindView(R.id.tv_count1)
    TextView tvCount1;
    @BindView(R.id.tv_count2)
    TextView tvCount2;
    @BindView(R.id.tv_count3)
    TextView tvCount3;
    @BindView(R.id.tv_count4)
    TextView tvCount4;
    @BindView(R.id.tv_count5)
    TextView tvCount5;
    @BindView(R.id.tv_count6)
    TextView tvCount6;
    @BindView(R.id.tv_count7)
    TextView tvCount7;

    @Inject
    AnalyzeViewModel analyzeViewModel;

    public static MonthlyTargetFragment newInstance() {

        return new MonthlyTargetFragment();
        // Required empty public constructor
    }

    @Override
    public void onLoadRetry() {
        if (!isNetworkConnected(getContext())){
            mHolder.showLoadingStatus(GlobalAdapter.NET_ERROR);
            return;
        }
        analyzeViewModel.getMonthlyTarget().observe(this, observer);
    }
    Observer observer= (Observer<BaseResponse<MonthlyTarget>>) monthlyTargetBaseResponse -> {
            if(monthlyTargetBaseResponse.isSuccess()){
                MonthlyTarget monthlyTarget=monthlyTargetBaseResponse.getData();
                tvClueConvertRate.setText(monthlyTarget.getClueConvertRate()+"%");
                tvFollowRate.setText(monthlyTarget.getFollowRate()+"%");
                tvCount1.setText(monthlyTarget.getNewCreateCustomerCount()+"");
                tvCount2.setText(monthlyTarget.getComeShopCount()+"");
                tvCount3.setText(monthlyTarget.getTestDriveCount()+"");
                tvCount4.setText(monthlyTarget.getOrderCount()+"");
                tvCount5.setText(monthlyTarget.getDeliveryCarCount()+"");
                tvCount6.setText(monthlyTarget.getDefeatedCount()+"");
                tvCount7.setText(monthlyTarget.getCancelOrderCount()+"");
            }
    };
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        onLoadRetry();
    }

    @Override
    public int layoutId() {
        return R.layout.fragment_monthly_target;
    }

    @Override
    public boolean initView() {
        getDigger().inject(this);
        return false;
    }

    @OnClick({R.id.ll_type1,R.id.ll_type2,R.id.ll_type3,R.id.ll_type4,R.id.ll_type5,R.id.ll_type6,R.id.ll_type7})
    public void click(View view){
        DailyTargetDetailFragmentArgs.Builder builder=new DailyTargetDetailFragmentArgs.Builder();
        builder.setType("monthly");
        switch (view.getId()){
            case R.id.ll_type1:
                builder.setTitle(getString(R.string.monthly_target_tag1));
                break;
            case R.id.ll_type2:
                builder.setTitle(getString(R.string.monthly_target_tag2));
                break;
            case R.id.ll_type3:
                builder.setTitle(getString(R.string.monthly_target_tag3));
                break;
            case R.id.ll_type4:
                builder.setTitle(getString(R.string.monthly_target_tag4));
                break;
            case R.id.ll_type5:
                builder.setTitle(getString(R.string.monthly_target_tag5));
                break;
            case R.id.ll_type6:
                builder.setTitle(getString(R.string.monthly_target_tag6));
                break;
            case R.id.ll_type7:
                builder.setTitle(getString(R.string.monthly_target_tag7));
                break;
        }
        go(null,R.id.action_monthlyFragment_to_dailyTargetDetailFragment,builder.build().toBundle());
    }

}
